/**
 * struct TreeNode {
 *	int val;
 *	struct TreeNode *left;
 *	struct TreeNode *right;
 * };
 */

class Solution {
public:
    /**
     * 
     * @param root TreeNode类 
     * @return int整型vector<vector<>>
     */
    vector<vector<int> >ans;
    void bfs(TreeNode* root,int level) {
        if((int)ans.size()<=level){
            ans.resize(level+1);
        }
        ans[level].emplace_back(root->val);
        if(root->left){
            bfs(root->left,level+1);
        }
        if(root->right){
            bfs(root->right,level+1);
        }
    }
    vector<vector<int> > levelOrder(TreeNode* root) {
        // write code here
        if(!root)return ans;
        bfs(root,0);
        return ans;
    }
};